﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<TireBias.Models.KANBANPlanModel.KANBANPlan_DS>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <style type="text/css">
br { clear: both; }
.cntSeparator {
    font-size: 54px;
    margin: 10px 7px;
    color: #000;
}
.desc { margin: 7px 3px; }
.desc div {
    float: left;
    font-family: Arial;
    width: 70px;
    margin-right: 65px;
    font-size: 13px;
    font-weight: bold;
    color: #000;
}
#fin
{
    background-color:Red;
    color:Black;
}
#fin:hover
{    
    color:White;
}
.cell
{
   line-height:25px !important;
 
}
.hide
{
    display:none;
}
.col
{ font-weight:bolder;
  
   padding: 4px 0px 4px 80px !important; 
   width: 50% !important; 
   text-align: left !important;
   background-color:#ccc !important;
}
input[type="text"]
{
        font-size: 1em;
        height: 1.5em;
        line-height: 2em;
        width: 90%;
}
</style>

<%
    var srcPDF = Url.Action("GetPDF") + "?code="+ Model._topcrdcd+"&sizes="+Model._sizes+"&forming="+Model._forming;
     %>



<table class="shadow" style=" width: 98%">
      <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._Text))
         {%>
      <tr>
         <td class="cell" style="font-size: x-large;line-height: 30px; 
            padding: 5px; background-color: #C38DEC;color:White" colspan="2">
            <%= Model._Text%>
         </td>
      </tr>
      <%} %>
      <tr class="rowb">
         <td class="head cell text-right" style="vertical-align: top; width:50%">                    
                <iframe src='<%=srcPDF%>' height="575px" width="100%"></iframe>
         
         </td>
         <td style="vertical-align:top;">
  
            <table width="100%" style="height:100%" id="detail">
            <tr> 
<td class="col cell" style="padding: 10px 0px; width: 25%;">
DATE-SEQ
<span class="fontTh">ล็อตที่ผลิต</span>
</td>
<td class="cell" id="seqDT">
<h3><%= Model._plandt %>-<%=Model._itemno %></h3>  
</td>
</tr>
 <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
            SIZE
            <span class="fontTh">ขนาดผ้าใบ</span>
         </td>
         <td class="cell" id="Td1">
         <h3> <%= Model._sizes %></h3>  
         </td>
      </tr>
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
            FORMING
           
            <span class="fontTh">เครื่องที่สร้าง</span>
         </td>
         <td class="cell" id="Td2">
        <h3>   <%= Model._forming %></h3> 
         </td>
      </tr>
     
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
            Topped Cord
            
            <span class="fontTh">ผ้าใบ</span>
         </td>
         <td class="cell" id="Td7">
         <h3>  <%= Model._topcrdcd%></h3> 
         </td>
      </tr>
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
            Tire Cord Lot
         
            <span class="fontTh">ผ้าใบ</span>
         </td>
         <td class="cell" id="Td8">
         <h3>  <%= Model._Tcrdlot %></h3> 
         </td>
      </tr>      
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
           Expired date
       
            <span class="fontTh">วันหมดอายุ</span>
         </td>
         <td class="cell">
         <h3>  <%= Model._topexp %></h3> 
         </td>
      </tr>
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
         Length (M.)
            
            <span class="fontTh">ความยาว(เมตร)</span>
         </td>
         <td class="cell" >
         <h3>  <%= Model._toplen %></h3> 
         </td>
      </tr>

            <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._P1))
         { %>
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
            P1
          
            <span class="fontTh">ความยาวผ้าใบชั้นที่ 1 (มม.)</span>
         </td>
         <td class=" cell" id="Td3">
     <h3>  <%= Model._P1%></h3>     
         </td>
      </tr>
      <% } %>
      <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._P2))
         { %>
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
            P2
            
            <span class="fontTh">ความยาวผ้าใบชั้นที่ 2 (มม.)</span>
         </td>
         <td class="cell" id="Td4">
        <h3>   <%= Model._P2%></h3> 
         </td>
      </tr>
      <% } %>
      <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._P3))
         { %>
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
            P3
         
            <span class="fontTh">ความยาวผ้าใบชั้นที่ 3 (มม.)</span>
         </td>
         <td class="cell" id="Td5">
           <h3> <%= Model._P3%></h3>
         </td>
      </tr>
      <% } %>
      <% if (WinNemoLib.StrUtil.IsNotEmpty(Model._P4))
         { %>
      <tr class="rowb">
         <td class="col cell" style="padding: 10px 0px; width: 25%;">
            P4
          
            <span class="fontTh">ความยาวผ้าใบชั้นที่ 4 (มม.)</span>
         </td>
         <td class="cell" id="Td6">
          <h3> <%= Model._P4%></h3> 
         </td>
      </tr>
      <% } %>
    <tr style="text-align: center; font-size: 6em; font-weight: bolder;  line-height: 150px;" class="head">
                  <td id="ply1" style="border:2px solid black !important;"  >
                      <%= Model._TmpP1 %>
                     </td>
                  <td id="ply2" style="border:2px solid black !important;" >
                     <%= Model._TmpP2  %>
                  </td>
               </tr>

               <tr class="rowb">
         <td class="col cell" style="width: 25%;">
           Standard Update
         </td>
         <td class="cell">
             <%= Model._fileSTDModifyBy %><br />
         <%= Model._fileSTDModifyDT %>
         </td>
         </tr>
         <tr>
            <td class="col cell" style="padding: 10px 0px; width: 25%;">
           Valid
         </td>
         <td class="cell">
       <%= Model._STDvalid %>
         </td>
      </tr>
<tr class="rowa" id="ang">
<td class="col cell" style="padding: 10px 0px; width: 25%;">
<span></span> Angle          
<span class="fontTh">องศาผ้าใบชั้นที่ </span><span></span>
</td>
<td class="cell" id="Td10">
<input type="text" value="<%= Model._angPly1 %>"   id="txtAngle" />
<input id="hdnAng" type="hidden" value="<%= Model._Angel %>" />
</td>
</tr>

     </table>            
            </td>
      </tr>
   </table>
   <br />
<div id="timer" style="margin-left:12%"  title="กรุณารอสักครู่...">
    <div id="counter_2" style="height: 77px; overflow: hidden;" >
    </div>
</div>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="FeaturedContent" runat="server">
    <section class="featured">
 <div class="content-wrapper" style="height:40px">
            <hgroup class="title float-left">
            <h1>Bias Head Computer</h1>
                <h2  style="padding-left:55px;">BIAS NO.<%: Model._biasno %></h2>      
             
            </hgroup> 
             <hgroup class="title float-right">
                <h3>
         Name :
         <% if (Request.IsAuthenticated)
            {  %>
         <%:  User.Identity.Name %>
         <% } %></h3>
            </hgroup>   
 </div>
 </section>
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="TableContent" runat="server">
<% if (WinNemoLib.StrUtil.IsNotEmpty(Model._Information))
    {%>
<div class="float-left" style="margin-left: 10px;">
          <input type="button" id="back" value="BACK" class="btnFooter"  
              style="height: 75px;  width: 200px;" />
        
</div>
<%} %>
<div class="float-left" style="margin-left: 250px;">
          <input type="button" id="fin" value="FINISHED" class="btnFooter"  
              style="height: 75px;  width: 200px;" />
        
</div>
<div class="float-left" style="margin-left: 50px;">
          <input type="button" id="new" value="NEW PLY" class="btnFooter"  style="height: 75px;  width: 200px;" />
        
</div>

    <div id="numericInput" style="float:left; width:300px;" >   
   <table id="keypad" class="hide">
         <tr style="background-color:#696969;"><td colspan="3" style="text-decoration:none; text-align:right;">
         <img src="<%: Url.Content("~/Images/power.png")%> "  alt='' width="100px" height="75px" id="close" />
         </td></tr>
         <tr class="rowa" >
            <td class="key">
               1
            </td>
            <td class="key ">
               2
            </td>
            <td class="key ">
               3
            </td>
         </tr>
         <tr class="rowa" >
            <td class="key ">
               4
            </td>
            <td class="key ">
               5
            </td>
            <td class="key ">
               6
            </td>
         </tr>
         <tr class="rowa" >
            <td class="key ">
               7
            </td>
            <td class="key ">
               8
            </td>
            <td class="key ">
               9
            </td>
         </tr>
         <tr class="rowa" >
            <td class="btn">
               DEL
            </td>
            <td class="key ">
               0
            </td>
            <td class="key ">
               .
            </td>
         </tr>
      </table>
</div>

    <div id="dialog-a" title="Wanning :  Confirm to Finish">
      <table style="width: 98%" class="fontTB">
         <tr class="rowa">
            <td class="head cell text-right" style="padding: 10px 0px; width: 30%">
               Emp code</td>
            <td class="cell">
               <input type="text" id="txtempnm" style="width: 75%" maxlength="6" />
            </td>
         </tr>
         <tr class="rowa">
            <td class="head cell text-right" style="padding: 10px 0px;">
               Password
            </td>
            <td class="cell">
               <input type="password" id="txtpass" style="width: 75%" />
            </td>
         </tr>
         <tr class="rowa">
            <td class="head cell text-right" style="padding: 10px 0px;">
               Short Text
            </td>
            <td class="cell">
               <input type="text" id="txtshort" style="width: 75%" maxlength="30" />
            </td>
         </tr>
      </table>
   </div>
   

</asp:Content>

<asp:Content ID="Content5" ContentPlaceHolderID="ScriptsSection" runat="server">
    <script src='<%: Url.Content("~/Scripts/autoNumeric.js") %>' type="text/javascript"></script>
    <script src='<%: Url.Content("~/Scripts/jquery.metadata.js") %>' type="text/javascript"></script>
    <% if (false)
   { %>
<script src="../../Scripts/jquery-1.7.1.js" type="text/javascript"></script>
<% } %>
<script type="text/javascript">
    $(function () {
        $("#numericInput").draggable();
        $("#txtAngle").attr("maxlength", 6).attr("mask", "999.99").autoNumeric({ vMin: '0', vMax: '999.99', aPad: false }).click(function (event) {
            var parentOffset = $(this).offset();
            var o = {
                left: 1000,
                top: 250
            };

            if ((clickNum == null) || ($(this).attr("id") == clickNum.attr("id"))) $("#keypad").slideToggle().offset(o);
            clickNum = $(this);
            event.stopPropagation();
        });

        var clickNum = null;
        $('.key').click(function (event) {

            var numBox = clickNum;
            if (clickNum.is(':disabled')) {
                return;
            }

            //            o = numBox.data('mask');
            //            o.maskArray = "999.99"
            var marks = (numBox).attr("mask");
            var max = (numBox).attr("maxlength").length;
            var maskArray = marks.split('');
            if (numBox.val().length == max) {
                return;
            }

            var v = $.trim(this.innerHTML);
            var valueArray = ($.trim(numBox.val())).split('')
            var idx = $.inArray(".", valueArray);

            if ((v == ".") && (idx > -1)) {
                return;
            }

            if ($.trim(this.innerHTML) == ".") {
                if ($.inArray(".", maskArray) < 0) {
                    return;
                }
                numBox.val(numBox.val() + '.');
                return;
            }

            var i = valueArray.length;


            if (idx >= 0) {
                var pt = maskArray.length - ($.inArray(".", maskArray));
                var x = valueArray.length + 1 - idx;
                if (x > pt) {
                    return;
                }
                i = $.inArray(".", maskArray) + 1;


            } else if ((i > 0) && (maskArray[i] == '.')) {
                numBox.val(numBox.val() + '.');
            }

            if (maskArray[i] == 'undefine') {
                return;
            }

            if (v <= maskArray[i]) {
                numBox.val(numBox.val() + v);
            }

            event.stopPropagation();
        });

        $('.btn,#close').click(function (event) {
            var numBox = clickNum
            if ($.trim(this.innerHTML) == 'DEL') {
                if (numBox.val().length > 0) {
                    clickNum.val(numBox.val().substring(0, numBox.val().length - 1));
                }
                else {
                    numBox.val('');
                }
            }
            else {
                $("#keypad").slideToggle();
                clickNum = null;
            }

            event.stopPropagation();
        });

        //End keypad
        var nextFinish;
        $("#timer").dialog({
            width: 350,
            modal: true,
            closeOnEscape: false,
            position: {
                my: 'center',
                at: 'center',
                of: $('#detail')
            },
            autoOpen: false,
            show: "blind",
            open: function (event, ui) {
                $(".ui-dialog-titlebar-close").hide();
                $('#counter_2').empty();
                $('#counter_2').removeClass("hide").countdown({
                    stepTime: 60,
                    image: '<%:Url.Content("~/images/digits.png")%>',
                    startTime: '01:00',
                    timerEnd: function () {
                        $("#timer").dialog("close");
                        $('#counter_2').empty();
                        window.location = nextFinish;
                    },
                    format: 'mm:ss'
                })
            }
        });

        $("#dialog-a").dialog({
            width: 650,
            height: 400,
            position: {
                my: 'center',
                at: 'center',
                of: $('#detail')
            },
            autoOpen: false,
            show: "blind",
            open: function (event, ui) {
                $(this).parent().children(".ui-widget-header").css("background", "#B22222");
                $(this).parent().children(".ui-dialog-titlebar").css("color", "white");
                $("#txtempnm").val("").focus();
                $("#txtpass").val("");
                $("#txtshort").val("");
            },
            buttons: {
                "Back": function () {
                    $(this).dialog("close");
                },
                "Confirm Finished": function () {

                    if ($("#txtempnm").val() == "") {
                        alert("ระบุข้อมูลไม่ครบ");
                        $("#TCLen").focus();
                        return;
                    }
                    if ($("#txtpass").val() == "") {
                        alert("ระบุข้อมูลไม่ครบ");
                        $("#TCLen").focus();
                        return;
                    }
                    if ($("#txtshort").val() == "") {
                        alert("ระบุข้อมูลไม่ครบ");
                        $("#TCLen").focus();
                        return;
                    }


                    $.post('<%=Url.Action("Get_Author","BiasHead") %>' + '?users=' + $("#txtempnm").val() + '&pass=' + $("#txtpass").val()
                    , function (data) {
                        if (data.success == 0) {
                            alert(data.message);
                        }
                        else {
                            finish();
                            $("#dialog-a").dialog("close");
                        }
                    });
                }
            }
        });

        $.post('<%= Url.Action("GET_NOTValue") %>' + '?seq=' + '<%= Model._plandt %>' + '-' + '<%=Model._itemno %>' + '&biasno=' + '<%: Model._biasno %>' + '&shift=' + '<%: Model._shift %>', function (data) {
            if (data.success <= 0) {
                $("#new").addClass("hide");
                $("#fin").click(function () {
                    //กรณีไม่มี ply เหลือแล้ว
                    var IntAng = parseFloat($("#hdnAng").val());
                    var ang = parseFloat($("#txtAngle").val());

                    if ($("#txtAngle").val() == "") {
                        alert("ระบุข้อมูลไม่ครบ");
                        $("#txtAngle").focus();
                        return;
                    } else if (!ang.between(IntAng - 1, IntAng + 1)) {
                        alert("Angle under and over standard (องศาไม่ถูกต้อง).");
                        return;
                    } else {
                        finish();
                    }
                });
            } else {
                $("#fin").click(function () {
                    //กด Finish เมื่อ ply เหลือ
                    var IntAng = parseFloat($("#hdnAng").val());
                    var ang = parseFloat($("#txtAngle").val());

                    if ($("#txtAngle").val() == "") {
                        alert("ระบุข้อมูลไม่ครบ");
                        $("#txtAngle").focus();
                        return;
                    } else if (!ang.between(IntAng - 1, IntAng + 1)) {
                        alert("Angle under and over standard (องศาไม่ถูกต้อง).");
                        return;
                    } else {
                        $("#dialog-a").dialog("open");
                    }

                });
            }
        });

        $("#back").click(function () {
            var getUsersUrl = '<%= Url.Action("GET_PDF_INF","BiasHead_Kanban") %>' + '?seq=' + '<%= Model._plandt %>' + '-' + '<%=Model._itemno %>' + '&biasno=' + '<%: Model._biasno %>' + '&shift=' + '<%: Model._shift %>';
            getUsersUrl = getUsersUrl + "&subItem=" + '<%=  Model._subItem%>';
            window.location = getUsersUrl;
        });



        function callScriptMethod(url, jsonObject, action, callback, async) {

            callback = callback || function () { };
            async = (async == null || async);
            if (action == "") {
                action = '<%= Url.Action("Header_line","BiasHead") %>' + '?biasno=' + '<%: Model._biasno %>' + '&shift=' + '<%: Model._shift %>'
            }
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: url,
                data: JSON.stringify(jsonObject),
                dataType: "json",
                async: async,
                success: function (data) {

                    if (data.success != "0") {
                        nextFinish = action; 
                        if (url == '<%= Url.Action("FINIS_TireSTD") %>') {
                            if (data.delays == "1") {
                             $("#timer").dialog("open");
                           return;
                            }
                        }
                        window.location = nextFinish;


                    } else alert(data.message);
                },
                error: function (xhr, status, error) {
                    var err = xhr.responseText;
                    alert(err.Message);
                }
            });
        }



        function finish() {
            var p1;
            if ($("#ply1").text() != "") {
                p1 = $("#txtAngle").val();
            }
            var p2;
            if ($("#ply2").text() != "") {
                p2 = $("#txtAngle").val();
            }

            var dataForSubmit = new Array();
            dataForSubmit.push({
                _biasno: '<%: Model._biasno %>',
                _plandt: '<%: Model._plandt %>',
                _itemno: '<%: Model._itemno %>',
                _size: '<%: Model._sizes %>',
                _empname: '<%: User.Identity.Name %>',
                _shift: '<%:Model._shift %>',
                _sitemno: '<%: Model._subItem %>',
                _sauthemp: $("#txtempnm").val(),
                _sshtxt: $("#txtshort").val(),
                _Ply1: p1,
                _Ply2: p2
            });
            var getUsersUrl = '<%= Url.Action("FINIS_TireSTD") %>';
            var nextUrl = '<%= Url.Action("Use_KANBAN","BiasHead") %>' + "?seq=" + '<%= Model._plandt %>' + '-' + '<%=Model._itemno %>'
            nextUrl = nextUrl + '&biasno=' + '<%: Model._biasno %>' + '&shift=' + '<%: Model._shift %>';
            callScriptMethod(getUsersUrl, { theData: dataForSubmit }, nextUrl);
        }

        Number.prototype.between = function (f, l) {

            first = parseFloat(f);
            last = parseFloat(l);
            return (first < last ? parseFloat(this) >= first && parseFloat(this) <= last : parseFloat(this) >= last && parseFloat(this) <= first);
        }
        $("#new").click(function () {
            var IntAng = parseFloat($("#hdnAng").val());
            var ang = parseFloat($("#txtAngle").val());

            if ($("#txtAngle").val() == "") {
                alert("ระบุข้อมูลไม่ครบ");
                $("#txtAngle").focus();
                return;
            } else if (!ang.between(IntAng - 1, IntAng + 1)) {
                alert("Angle under and over standard (องศาไม่ถูกต้อง).");
                return;
            } else {
                var dataForSubmit = new Array();
                var p1;
                if ($("#ply1").text() != "") {
                    p1 = $("#txtAngle").val();
                }
                var p2;
                if ($("#ply2").text() != "") {
                    p2 = $("#txtAngle").val();
                }
                dataForSubmit.push({
                    _biasno: '<%: Model._biasno %>',
                    _plandt: '<%: Model._plandt %>',
                    _itemno: '<%: Model._itemno %>',
                    _empname: '<%: User.Identity.Name.ToString() %>',
                    _shift: '<%:Model._shift %>',
                    _sitemno: '<%: Model._subItem %>',
                    _sauthemp: $("#txtempnm").val(),
                    _sshtxt: $("#txtshort").val(),
                    _Ply1: p1,
                    _Ply2: p2
                });
                var getUsersUrl = '<%= Url.Action("UPDATE_ANG") %>';
                var action = '<%= Url.Action("Use_KANBAN","BiasHead") %>' + "?seq=" + '<%= Model._plandt %>' + '-' + '<%=Model._itemno %>';
                callScriptMethod(getUsersUrl, { theData: dataForSubmit }, action);
                //   window.location = getUsersUrl;
            }
        });




    });
</script>

</asp:Content>
